package com.appistry.maven.plugin.far.remote.ssh;

import com.jcraft.jsch.JSchException;

/**
 * <code>Command</code> implementation for executing commands on a remote host
 * over SSH.
 * 
 * The actual SSH functionality is encapsulated in the <code>Ssh</code> class
 * 
 */
public class SshCommand implements Command {

	/**
	 * Receiver/target object whose method will be called by the
	 * <code>Command</code>'s <code>execute</code> method. In this case,
	 * <code>Ssh</code> class
	 */
	private RemoteOperation ssh;

	public SshCommand() {
		super();
	}

	public SshCommand(RemoteOperation ssh) {
		super();
		this.ssh = ssh;
	}

	public RemoteOperation getRemoteOperation() {
		return ssh;
	}

	public void setRemoteOperation(RemoteOperation ssh) {
		this.ssh = ssh;
	}

	/**
	 * Calls <code>Ssh</code> <code>sendCommand</code> that executes the command
	 * 
	 * @throws Exception
	 *             wraps JSchExpcetion
	 */
	public void execute() throws Exception {
		try {
			ssh.run();
		} catch (JSchException jse) {
			throw jse;
		}
	}

}
